package com.dingding.order.core.march.dao.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.dao.impl.BaseDaoImpl;
import com.dingding.common.core.beans.Userordert;
import com.dingding.common.core.util.DateFormatUtil;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.order.code.order.PublishCarType;
import com.dingding.order.core.march.dao.IMarchUserOrderTDao;
import com.dingding.order.core.march.sql.MarchOrderDaoSql;
import com.dingding.order.dto.march.ReqMarchOrderDTO;
import com.dingding.order.dto.march.ResMarchOrderDTO;
import com.dingding.order.dto.march.ResTaxiMarchOrder;
import com.dingding.order.dto.march.underway.UderWayOrderDto;

/**
 * 
 * @ClassName: LatelyOrderDaoImpl
 * @Description: 进行中订单 Dao实现
 * @author chenwei
 * @date 2016年6月3日 上午11:50:48
 * @version 叮叮搭车V2.2
 * 
 */
@Component("marchUserOrderTDao")
public class MarchUserOrderTDaoImpl extends BaseDaoImpl<Userordert> implements IMarchUserOrderTDao {

	/** 
	 * 
	 * @Title: marchOrder
	 * @Description: 获取进行中订单
	 * @return List<ResMarchOrderDTO> 所属用户的当前订单
	 * @author chenwei
	 * 
	 * 
	 *         修改说明： 由于当前代码重构是在新版本发布之前，故不存在兼容性问题，所以重构之前的代码不再保存 修改人：CHEHUANBO
	 *         修改原因：代码逻辑存在问题，重构代码 修改时间：2016-06-12 修改版本：V2.2.0
	 * 
	 */
	@Override
	@Transactional(readOnly = true)
	public List<ResMarchOrderDTO> getMarchOrderDaoList(ReqMarchOrderDTO reqMarchOrder) {

		// 从数据库中获取所属当前用户的进行中订单
		List<Object[]> objects = this.getMarchOrderByDb(reqMarchOrder);
		// 创建查看最近订单响应Bean
		List<ResMarchOrderDTO> resMarchOrderDTOs = this.convertToDataBean(objects, reqMarchOrder);

		return resMarchOrderDTOs;
	}

	/**
	 * @Title: getTaxiMarchOrderDaoList
	 * @Description:获取出租车进行中订单列表
	 * @author zhouxuan
	 * @since V2.3.0
	 */
	@Transactional(readOnly = true)
	public List<ResTaxiMarchOrder> getTaxiMarchOrderDaoList(ReqMarchOrderDTO reqMarchOrderDTO) {
		// 从数据库中获取所属当前用户的出租车进行中订单
		List<Object[]> taxiObjects = this.getTaxiMarchOrder(reqMarchOrderDTO);
		// 数据转换
		List<ResTaxiMarchOrder> resTaxiMarchOrders = this.taxiConvertBean(taxiObjects, reqMarchOrderDTO);
		return resTaxiMarchOrders;
	}

	/**
	 * @Title: taxiConvertBean
	 * @Description:将数据库数据转换为bean
	 * @author zhouxuan
	 * @since V2.3.0
	 */
	private List<ResTaxiMarchOrder> taxiConvertBean(List<Object[]> objects, ReqMarchOrderDTO reqMarchOrder) {
		// 创建转换bean
		List<ResTaxiMarchOrder> resTaxiMarchOrders = new ArrayList<ResTaxiMarchOrder>();
		// 订单依次转换
		for (Object[] obj : objects) {
			// 临时转换对象
			ResTaxiMarchOrder resTaxiMarchOrder = new ResTaxiMarchOrder();

			// 当前服务器时间
			resTaxiMarchOrder.setCurrentSerTime(new Date());
			// 订单里程
			if (obj[0] != null) {
				resTaxiMarchOrder.setDistance(new BigDecimal(obj[0].toString()));
			}
			// 终点
			if (obj[1] != null) {
				resTaxiMarchOrder.setEndAddress(obj[1].toString());
			}
			// 终点纬度
			if (obj[2] != null) {
				resTaxiMarchOrder.setEndLatitude(ToolUtil.castDouble(obj[2]));
			}
			// 终点经度
			if (obj[3] != null) {
				resTaxiMarchOrder.setEndLongitude(ToolUtil.castDouble(obj[3]));
			}
			// obj[4]抢单用户ID obj[11]下单用户id
			if (obj[4] != null) { // 有抢单
				if (obj[4].toString().equals(reqMarchOrder.getUserId())) {
					// 用户是司机
					if (obj[11] != null) {
						resTaxiMarchOrder.setOtherUserId(obj[11].toString());
					}
				} else {
					// 用户是乘客
					resTaxiMarchOrder.setOtherUserId(obj[4].toString());
				}
			} else {
				// 下单用户ID
				if (obj[11] != null) {
					resTaxiMarchOrder.setOtherUserId(obj[11].toString());
				}
			}

			// 车辆车牌号
			if (obj[5] != null) {
				resTaxiMarchOrder.setLicensePlate(obj[5].toString());
			}
			// 留言（可为空）
			if (obj[6] != null) {
				resTaxiMarchOrder.setMessage(obj[6].toString());
			}
			// 对方用户名称（称呼）
			if (obj[7] != null) {
				resTaxiMarchOrder.setNickName(obj[7].toString());
			}
			// 人数（默认1）
			if (obj[8] != null) {
				resTaxiMarchOrder.setNumber(ToolUtil.castInteger(obj[8].toString()));
			}
			// 订单Id
			if (obj[9] != null) {
				resTaxiMarchOrder.setOid(obj[9].toString());
			}
			// 订单状态
			if (obj[10] != null) {
				resTaxiMarchOrder.setOrderStatus(ToolUtil.castInteger(obj[10]));
			}
			// 出发时间
			String titleTime = null;
			if (obj[12] != null) {
				titleTime = DateFormatUtil.getMMddEHHss(obj[12]);
				resTaxiMarchOrder.setSetOutTime(titleTime);
				resTaxiMarchOrder.setOutTime((Date) obj[12]);
			}
			// 对方性别
			if (obj[13] != null) {
				resTaxiMarchOrder.setSex(ToolUtil.castInteger(obj[13]));
			}
			// 起点
			if (obj[14] != null) {
				resTaxiMarchOrder.setStartAddress(obj[14].toString());
			}
			// 起点纬度
			if (obj[15] != null) {
				resTaxiMarchOrder.setStartLatitude(ToolUtil.castDouble(obj[15]));
			}
			// 起点经度
			if (obj[16] != null) {
				resTaxiMarchOrder.setStartLongitude(ToolUtil.castDouble(obj[16]));
			}
			// 对方手机号
			if (obj[17] != null) {
				resTaxiMarchOrder.setTelePhone(obj[17].toString());
			}
			// 乘车费用(总金额)
			if (obj[18] != null) {
				resTaxiMarchOrder.setTotalMoney(new BigDecimal(obj[18].toString()));
			}
			// 对方用户头像访问地址
			if (obj[19] != null) {
				resTaxiMarchOrder.setUserAvatar(ToolUtil.imageAddress(obj[19].toString()));
			}
			// 用户级别
			if (obj[20] != null) {
				resTaxiMarchOrder.setUserLevel(new BigDecimal(obj[20].toString()));
			}
			// 缩略图头像地址
			if (obj[21] != null) {
				resTaxiMarchOrder.setUserTabloidAvatar(ToolUtil.imageAddress(obj[21].toString()));
			}
			// 抢单时的用户类型
			if (obj[4] != null && obj[4].toString().equals(reqMarchOrder.getUserId())) {
				resTaxiMarchOrder.setUserType(1); // 1：车主2：乘客
			} else {
				resTaxiMarchOrder.setUserType(2); // 1：车主2：乘客
			}
			// 车辆颜色
			if (obj[22] != null) {
				resTaxiMarchOrder.setVehicleColor(obj[22].toString());
			}
			// 车辆型号
			if (obj[23] != null) {
				resTaxiMarchOrder.setVehicleModel(obj[23].toString());
			}
			// 车辆类型
			if (obj[24] != null) {
				resTaxiMarchOrder.setVehicleType(obj[24].toString());
			}
			// 标题
			resTaxiMarchOrder.setTitle(titleTime);

			resTaxiMarchOrders.add(resTaxiMarchOrder);
		}
		return resTaxiMarchOrders;
	}

	/**
	 * 
	 * @Title: getTaxiMarchOrder
	 * @Description:获取出租车订单
	 * @author zhouxuan
	 * @since V2.3.0
	 */
	@Transactional(readOnly = true)
	private List<Object[]> getTaxiMarchOrder(ReqMarchOrderDTO reqMarchOrderDTO) {
		// 创建存储用户出租车待完成订单的集合对象
		List<Object[]> taxiObjects = new ArrayList<Object[]>();
		try {
			// 根据用户ID获取未完成的出租车订单
			taxiObjects = super.listSqlObj(MarchOrderDaoSql.GET_LAST_USER_TAXI_ORDER, reqMarchOrderDTO.getUserId(),
					reqMarchOrderDTO.getUserId());
			
			// 获取待抢单的出租车订单
			List<Object[]> objects = super.listSqlObj(MarchOrderDaoSql.GET_TO_BE_PAID_TAXI_ORDER, reqMarchOrderDTO.getUserId(),
					reqMarchOrderDTO.getUserId());
			
			taxiObjects.addAll(objects);
			
		} catch (Exception e) {
			log.error("根据用户Id获取其出租车待完成订单时出现异常 类：" + this.getClass(), e);
		}
		return taxiObjects;
	}

	/**
	 * 从数据库中获取所属当前用户的进行中订单
	 * 
	 * @Title: getMarchOrderByDb
	 * @param reqMarchOrderDTO
	 *            客户端请求参数DTO
	 * @return List<Object[]> 所属当前用户的进行中订单
	 * @author CHEHUANBO
	 */
	@Transactional(readOnly = true)
	private List<Object[]> getMarchOrderByDb(ReqMarchOrderDTO reqMarchOrderDTO) {

		// 创建存储用户待完成订单的集合对象
		List<Object[]> objects = new ArrayList<Object[]>();

		try {
			// 根据用户Id获取其待完成订单
			objects = super.listSqlObj(MarchOrderDaoSql.GET_LAST_USER_ORDER, reqMarchOrderDTO.getUserId(),
					reqMarchOrderDTO.getUserId(), reqMarchOrderDTO.getUserId());
		} catch (Exception e) {
			log.error("根据用户Id获取其待完成订单时出现异常 类：" + this.getClass(), e);
			return objects;
		}

		return objects;

	}

	/**
	 * @Title: setUserType @Description: 判断当前用户角色并赋值 @param reqGetLastUserOrder
	 *         请求参数 @param resGetLastUserOrder 响应Bean @return void 返回类型 @throws
	 */
	public void setUserType(ReqMarchOrderDTO reqMarchOrder, ResMarchOrderDTO resMarchOrder) {

		// 本订单中该用户的角色 1：车主2：乘客
		if (ToolUtil.isBlank(resMarchOrder.getGrabOrderUserId())) {

			// 判断如果没有抢单用户
			if (resMarchOrder.getOrderType().equals(1)) {
				resMarchOrder.setUserType(2);// 当前用户角色为乘客
			} else if (resMarchOrder.getOrderType().equals(2)) {
				resMarchOrder.setUserType(1);// 当前用户角色为司机
			}

		} else if (ToolUtil.isNotBlank(resMarchOrder.getGrabOrderUserId())) {

			if (resMarchOrder.getPlaceOrderUserId().equals(reqMarchOrder.getUserId())) {

				if (resMarchOrder.getOrderType().equals(1)) {
					resMarchOrder.setUserType(2);// 当前用户角色为乘客
				} else if (resMarchOrder.getOrderType().equals(2)) {
					resMarchOrder.setUserType(1);// 当前用户角色为司机
				}

			} else if (resMarchOrder.getGrabOrderUserId().equals(reqMarchOrder.getUserId())) {

				if (resMarchOrder.getOrderType().equals(1)) {
					resMarchOrder.setUserType(1);// 当前用户角色为司机
				} else if (resMarchOrder.getOrderType().equals(2)) {
					resMarchOrder.setUserType(2);// 当前用户角色为乘客
				}
			}
		}
	}

	/**
	 * 
	 * 
	 * @Title: getResGetLastUserOrder
	 * @Description: 将数据库查询出的数据原生进行中订单数据转换成数据Bean
	 * @param obj
	 *            数据库中原生数据对象
	 * @param reqMarchOrder
	 *            客户端请求参数
	 * @author chenwei
	 * @return List<ResMarchOrderDTO> 进行中订单转换后的数据Bean
	 * 
	 *         修改说明： 由于当前代码重构是在新版本发布之前，故不存在兼容性问题，所以重构之前的代码不再保存 修改人：CHEHUANBO
	 *         修改原因：代码存在问题，重构代码 修改时间：2016-06-12 修改版本：V2.2.0
	 * 
	 * 
	 * 修改人：余海清
	 * 修改时间：2016-10-17
	 * 修改版本：V2.5.2
	 * 修改原因：存在两个或两个以上的待抢单订单时，返回数据不正确;获取到的进行中订单列表未做非空判断
	 * 修改内容：删除336~338行代码 
	 * if(objects.size() > 1 && obj[15] != null && ToolUtil.castInteger(obj[15]) == 1){
	 *		continue;
	 *	}
	 * 
	 */
	private List<ResMarchOrderDTO> convertToDataBean(List<Object[]> objects, ReqMarchOrderDTO reqMarchOrder) {

		// 将查询到的数据库数据转换成数据Bean
		List<ResMarchOrderDTO> marchOrderList = new ArrayList<ResMarchOrderDTO>();

		if(objects == null || objects.size() <= 0){
			return marchOrderList;
		}
		
		for (Object[] obj : objects) {

			// 创建查看最近订单的响应Bean对象
			ResMarchOrderDTO resMarchOrderDTO = new ResMarchOrderDTO();

			// 对方用户Id
			if (obj[0] != null) {
				resMarchOrderDTO.setUserId(obj[0].toString());
				resMarchOrderDTO.setOtherUserId(obj[0].toString());
			}
			// 对方用户姓名
			if (obj[1] != null) {
				resMarchOrderDTO.setNickName(obj[1].toString());
			}
			// 对方用户头像
			if (obj[2] != null) {
				resMarchOrderDTO.setUserAvatar(ToolUtil.imageAddress(obj[2].toString()));
			}
			// 对方用户电话
			if (obj[3] != null) {
				resMarchOrderDTO.setTelePhone(obj[3].toString());
				resMarchOrderDTO.setTelNo(obj[3].toString());
			}
			String titleTime = null;
			// 出发时间
			if (obj[4] != null) {

				titleTime = DateFormatUtil.getMMddEHHss(obj[4]);

				resMarchOrderDTO.setSetOutTime(titleTime);
				resMarchOrderDTO.setOutTime(DateFormatUtil.yyyy_MM_dd_HHmmss(obj[4].toString()));
			}
			// 总金额
			if (obj[5] != null) {

				Integer userType = 0; // 当前用户角色
				BigDecimal couponMoney = new BigDecimal(0); // 优惠券金额

				// 下单类型 2：乘客下单 1：车主下单
				if (obj[17] != null && obj[18] != null) {

					if (ToolUtil.castInteger(obj[17]) == 1 && reqMarchOrder.getUserId().equals(obj[18].toString())) {
						userType = 1;
					} else if (ToolUtil.castInteger(obj[17]) == 2
							&& reqMarchOrder.getUserId().equals(obj[18].toString())) {
						userType = 2;
					} else if (ToolUtil.castInteger(obj[17]) == 1
							&& !reqMarchOrder.getUserId().equals(obj[18].toString())) {
						userType = 2;
					} else if (ToolUtil.castInteger(obj[17]) == 2
							&& !reqMarchOrder.getUserId().equals(obj[18].toString())) {
						userType = 1;
					}

				}

				if (obj[26] != null) {
					couponMoney = new BigDecimal(obj[26].toString());
				}

				if (userType == 1) {
					// 总金额
					resMarchOrderDTO.setTotalMoney(new BigDecimal(obj[5].toString()));
					// 订单费用
					resMarchOrderDTO.setOrderCost(new BigDecimal(obj[5].toString()));
					// 优惠券金额
					resMarchOrderDTO.setCouponMoney(new BigDecimal(0));
				} else if (userType == 2) {

					BigDecimal totalMoney = new BigDecimal(obj[5].toString()).add(new BigDecimal(2));

					// 实际支付金额
					totalMoney = totalMoney.subtract(couponMoney);

					if (totalMoney.compareTo(new BigDecimal(0)) < 0) {
						totalMoney = new BigDecimal(0);
					}

					// 总金额
					resMarchOrderDTO.setTotalMoney(totalMoney);
					// 订单费用
					resMarchOrderDTO.setOrderCost(new BigDecimal(obj[5].toString()));
					// 平台费用
					resMarchOrderDTO.setPlatformCost(new BigDecimal(2));
					// 优惠券金额
					resMarchOrderDTO.setCouponMoney(couponMoney);
				}

			}
			// 红包
			if (obj[6] != null) {
				resMarchOrderDTO.setRedBag(ToolUtil.castDouble(obj[6]));
			}
			// 留言
			if (obj[7] != null) {
				resMarchOrderDTO.setMessage(obj[7].toString());
			}
			// 搭乘人数
			if (obj[8] != null) {
				resMarchOrderDTO.setNumber(ToolUtil.castInteger(obj[8]));
			}
			// 开始地址
			if (obj[9] != null) {
				resMarchOrderDTO.setStartAddress(obj[9].toString());
			}
			// 开始经度
			if (obj[10] != null) {
				resMarchOrderDTO.setStartLongitude(ToolUtil.castDouble(obj[10]));
			}
			// 开始纬度
			if (obj[11] != null) {
				resMarchOrderDTO.setStartLatitude(ToolUtil.castDouble(obj[11]));
			}
			// 目的地
			if (obj[12] != null) {
				resMarchOrderDTO.setEndAddress(obj[12].toString());
			}
			// 目的地经度
			if (obj[13] != null) {
				resMarchOrderDTO.setEndLongitude(ToolUtil.castDouble(obj[13]));
			}
			// 目的地纬度
			if (obj[14] != null) {
				resMarchOrderDTO.setEndLatitude(ToolUtil.castDouble(obj[14]));
			}
			// 订单状态
			if (obj[15] != null) {
				resMarchOrderDTO.setOrderStatus(ToolUtil.castInteger(obj[15]));
			}
			// 下单类型 1：乘客下单 2：车主下单
			if (obj[17] != null) {

				// 下单用户角色
				Integer userType = ToolUtil.castInteger(obj[17]);

				resMarchOrderDTO.setOrderType(userType);

				if (userType == 1) {// 车主下单

					// 父订单
					if (obj[30] != null) {
						resMarchOrderDTO.setParentOrder(obj[30].toString());
						resMarchOrderDTO.setSubOrder(obj[16].toString());
					} else {
						resMarchOrderDTO.setParentOrder(obj[16].toString());
						resMarchOrderDTO.setSubOrder(null);
					}
				} else {// 乘客下单

					// 父订单
					if (obj[30] != null) {
						resMarchOrderDTO.setParentOrder(obj[30].toString());
						resMarchOrderDTO.setSubOrder(obj[16].toString());
					} else {
						resMarchOrderDTO.setParentOrder(null);
						resMarchOrderDTO.setSubOrder(obj[16].toString());
					}

				}

			}
			// 下单用户Id
			if (obj[18] != null) {
				resMarchOrderDTO.setPlaceOrderUserId(obj[18].toString());
			}
			// 抢单用户Id
			if (obj[19] != null) {
				resMarchOrderDTO.setGrabOrderUserId(obj[19].toString());
			}
			// 订单有效时间
			if (obj[20] != null) {
				resMarchOrderDTO.setOrderValidateTime((Date) obj[20]);
			}
			// 头像缩略图
			if (obj[21] != null) {
				resMarchOrderDTO.setUserTabloidAvatar(ToolUtil.imageAddress(obj[21].toString()));
			}
			// 订单里程
			if (obj[22] != null) {
				resMarchOrderDTO.setDistance(new BigDecimal(obj[22].toString()));
			}
			// 对方性别
			if (obj[23] != null) {
				resMarchOrderDTO.setSex(ToolUtil.castInteger(obj[23]));
			}
			// 短长途类型
			if (obj[24] != null) {
				resMarchOrderDTO.setIsLongDistance(ToolUtil.castInteger(obj[24]));
			}
			// 用户优惠券Id
			if (obj[25] != null) {
				resMarchOrderDTO.setUcId(obj[25].toString());
			}
			// 用户级别
			if (obj[27] != null) {
				resMarchOrderDTO.setUserLevel(new BigDecimal(obj[27].toString()));
			}
			// 出发条件 1:准点出发 2：出发前后15分钟
			if (obj[28] != null) {
				resMarchOrderDTO.setSetOutCondition(ToolUtil.castInteger(obj[28]));
			}

			// 是否合乘 1：合乘 2：不合乘
			if (obj[29] != null) {
				resMarchOrderDTO.setIsCarShare(ToolUtil.castInteger(obj[29]));
			}

			if (obj.length > 31) {
				// 车辆品牌
				if (obj[31] != null) {
					resMarchOrderDTO.setVehicleType(obj[31].toString());
				}
				// 车辆型号
				if (obj[32] != null) {
					resMarchOrderDTO.setVehicleModel(obj[32].toString());
				}
				// 车辆颜色
				if (obj[33] != null) {
					resMarchOrderDTO.setVehicleColor(obj[33].toString());
				}
				// 车辆图片
				if (obj[34] != null) {
					resMarchOrderDTO.setLicensePlate(ToolUtil.imageAddress(obj[34].toString()));
				}
				// 车牌号
				if (obj[35] != null) {
					resMarchOrderDTO.setLicensePlate(obj[35].toString());
				}
			}

			StringBuffer sBuffer = new StringBuffer();

			sBuffer.append(titleTime);

			resMarchOrderDTO.setTitle(sBuffer.toString());

			// 当前用在订单中的角色
			this.setUserType(resMarchOrderDTO, reqMarchOrder);

			// 当前服务器时间
			resMarchOrderDTO.setCurrentSerTime(new Date());

			marchOrderList.add(resMarchOrderDTO);
		}

		return marchOrderList;
	}

	/**
	 * @Title: setUserType
	 * @Description: 判断当前用户角色并赋值
	 * @param reqGetLastUserOrder
	 *            请求参数
	 * @param resGetLastUserOrder
	 *            响应Bean
	 * @return void 返回类型 @throws
	 */
	public void setUserType(ResMarchOrderDTO resMarchOrderDTO, ReqMarchOrderDTO reqMarchOrder) {

		// 本订单中该用户的角色 1：车主2：乘客
		if (ToolUtil.isBlank(resMarchOrderDTO.getGrabOrderUserId())) {

			resMarchOrderDTO.setUserType(resMarchOrderDTO.getOrderType());// 当前用户角色

		} else if (ToolUtil.isNotBlank(resMarchOrderDTO.getGrabOrderUserId())) {

			if (resMarchOrderDTO.getPlaceOrderUserId().equals(reqMarchOrder.getUserId())) {

				resMarchOrderDTO.setUserType(resMarchOrderDTO.getOrderType());// 当前用户角色

			} else if (resMarchOrderDTO.getGrabOrderUserId().equals(reqMarchOrder.getUserId())) {

				if (resMarchOrderDTO.getOrderType().equals(1)) {
					resMarchOrderDTO.setUserType(2);// 当前用户角色为司机
				} else if (resMarchOrderDTO.getOrderType().equals(2)) {
					resMarchOrderDTO.setUserType(1);// 当前用户角色为乘客
				}

			}
		}
	}

	/**
	 * @Description:获取顺风车的进行中订单集合
	 * @param userId 用户id
	 * @author fengshuonan
	 * @since 2.4
	 * 
	 * 
	 * 修改人：余海清
	 * 修改时间：2016-10-19
	 * 修改版本：2.5.2
	 * 修改原因：进行中订单合拼订单的父订单也一并显示在列表中，这是错误的显示方式
	 * 修改内容：
	 * if(oldDto.getOrderStatus() == 2 && oldDto.getParentOrder() == null){
	 *		continue;
	 * }
	 */
	@Override
	public List<UderWayOrderDto> getShunfengUnderWayOrder(String userId) {
		
		ReqMarchOrderDTO req = new ReqMarchOrderDTO();
		req.setUserId(userId);
		List<ResMarchOrderDTO> oldList = this.getMarchOrderDaoList(req);
		if(oldList == null || oldList.size() == 0){
			return new ArrayList<UderWayOrderDto>();
		}
		
		List<UderWayOrderDto> newList = new ArrayList<UderWayOrderDto>();
		for(int i=0;i<oldList.size();i++){
			ResMarchOrderDTO oldDto = oldList.get(i);
			
			// 当订单为已抢单状态，并且父订单为空时，该订单为平车主单，不用做显示。
			if((oldDto.getParentOrder() == null && oldDto.getOrderStatus() == 2)){
				continue;
			}
			
			UderWayOrderDto resUnderWayOrder = new UderWayOrderDto();
			
			resUnderWayOrder.setSetOutTime(DateFormatUtil.parseMMddWWHHSS(oldDto.getSetOutTime()));//出发时间标准格式
			resUnderWayOrder.setOutTime(oldDto.getSetOutTime());		//设置显示用的出发时间
			resUnderWayOrder.setOrderValidateTime(oldDto.getOutTime());	//设置订单生效时间
			BeanUtils.copyProperties(oldDto, resUnderWayOrder);
			resUnderWayOrder.setPublishType(PublishCarType.SHUN_FENG_CHE.getCode());
			newList.add(resUnderWayOrder);
		}
		
		return newList;
	}

	
	/**
	 * @Description:获取出租车的进行中订单集合
	 * @param userId 用户id
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public List<UderWayOrderDto> getTaxiUnderWayOrder(String userId) {
		
		ReqMarchOrderDTO req = new ReqMarchOrderDTO();
		req.setUserId(userId);
		List<Object[]> taxiObjects = this.getTaxiMarchOrder(req);
		List<ResTaxiMarchOrder> oldList = this.taxiConvertBean(taxiObjects, req);
		if(oldList == null || oldList.size() == 0){
			return new ArrayList<UderWayOrderDto>();
		}
		
		List<UderWayOrderDto> newList = new ArrayList<UderWayOrderDto>();
		for(int i=0;i<oldList.size();i++){
			UderWayOrderDto resUnderWayOrder = new UderWayOrderDto();
			ResTaxiMarchOrder oldDto = oldList.get(i);
			BeanUtils.copyProperties(oldDto, resUnderWayOrder);
			resUnderWayOrder.setPublishType(PublishCarType.TAXI.getCode());
			resUnderWayOrder.setSetOutTime(oldDto.getOutTime());//设置标准格式的出发时间
			resUnderWayOrder.setOutTime(oldDto.getSetOutTime());//设置显示用的出发时间
			resUnderWayOrder.setOrderValidateTime(resUnderWayOrder.getCreatTime());//设置订单的生效时间
			newList.add(resUnderWayOrder);
		}
		
		return newList;
	}
	
	
}
